package cn.zz.veggie.web.controller.mgmt;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.core.types.result.PageResult;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.ShopQuoteAppService;
import cn.zz.veggie.web.types.dto.mgmt.quote.MgmtProductQuoteQueryDto;
import cn.zz.veggie.web.types.dto.mgmt.quote.MgmtShopQuoteQueryDto;
import cn.zz.veggie.web.types.dto.mgmt.quote.MgmtShopQuoteSaveDto;
import cn.zz.veggie.web.types.vo.mgmt.MgmtProductQuoteVo;
import cn.zz.veggie.web.types.vo.mgmt.quote.MgmtShopQuoteVo;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * @author zhongq
 * @since 2024/7/28
 */
@Validated
@BoxRespResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/mgmt/shop-quote")
public class MgmtShopQuoteController {

	private final ShopQuoteAppService shopQuoteAppService;

	/**
	 * 报价列表
	 */
	@GetMapping("/list")
	public PageResult<MgmtShopQuoteVo> list(@Validated MgmtShopQuoteQueryDto dto,
			@RequestParam(defaultValue = "1") @Positive Integer current,
			@RequestParam(defaultValue = "10") @Positive Integer size) {
		return shopQuoteAppService.mgmtGetQuotes(dto, PageQuery.of(current, size));
	}

	/**
	 * 保存报价
	 */
	@PostMapping("/save")
	public void price(@RequestBody @Validated MgmtShopQuoteSaveDto dto) {
		shopQuoteAppService.mgmtChangeQuote(dto);
	}

	/**
	 * 通过商品名以及价格
	 */
	@PostMapping("/products")
	public List<MgmtProductQuoteVo> products(@Validated @RequestBody MgmtProductQuoteQueryDto dto) {
		return shopQuoteAppService.mgmtGetProductQuotes(dto);
	}

}